home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_ghostscript.idb / usr / freeware / lib / ghostscript / 3.33 / wftopfa.ps.z / wftopfa.ps
Encoding:
Text File  |  1998-05-21  |  8.5 KB  |  299 lines

  1. %    Copyright (C) 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of GNU Ghostscript.
  3. % GNU Ghostscript is distributed in the hope that it will be useful, but
  4. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility to
  5. % anyone for the consequences of using it or for whether it serves any
  6. % particular purpose or works at all, unless he says so in writing.  Refer
  7. % to the GNU Ghostscript General Public License for full details.
  8.  
  9. % wftopfa.ps
  10. % Convert a Wadalab base font to .PFA (or .PFB) format.
  11.  
  12. (gs_ksb_e.ps) run
  13. (wrfont.ps) run
  14.  
  15. /wftopfa_dict 100 dict def
  16. wftopfa_dict begin
  17.  
  18. /KanjiSubEncoding dup .findencoding def
  19.  
  20. % Initialize parameters.
  21. /init            % - init -
  22.  { /chars 256 dict def
  23.    /version (001.001) def
  24.    /highcode 0 def
  25.    /StdHW [32] def
  26.    /StdVW [32] def
  27.    /UniqueID 20000000 def
  28.    /FontBase (Wadalab) def
  29.    /StdEncMode false def
  30.    /CustomEncMode false def
  31.    /Binary false def
  32.    /Encrypt true def
  33.  } bind def
  34.  
  35. % Read definitions.
  36. /rdstring 5000 string def
  37. /readdefs        % <filename> readdefs -
  38.  { (r) file
  39.     { dup rdstring readline not { pop exit } if
  40.       dup length 15 ge
  41.        { dup dup length 7 sub 7 getinterval (> CompD) eq
  42.       { token pop exch token pop exch pop
  43.         dup 0 get /highcode exch def
  44.         exch chars 3 1 roll put
  45.       }
  46.       { pop
  47.       }
  48.      ifelse
  49.        }
  50.        { pop
  51.        }
  52.       ifelse
  53.     }
  54.    loop closefile
  55.  } bind def
  56.  
  57. % Write out the final font.
  58. /writepfa
  59.  { 4 string highcode 16#1000 add 16 2 index cvrs 0 (.r) putinterval
  60.      FontBase exch concatstrings /fullname exch def
  61.    UniqueID 20000000 eq { /UniqueID 4990000 highcode add def } if
  62.    /encoding CustomEncMode
  63.     { KanjiSubEncoding }
  64.     { StdEncMode { StandardEncoding } { ISOLatin1Encoding } ifelse }
  65.    ifelse def
  66.  
  67.    /Font 30 dict def
  68.    Font begin
  69.    /FontInfo 20 dict def
  70.    FontInfo begin
  71.  
  72.         % Write the clear text part.
  73.  
  74.    /CreationDate (%Calendar%) currentdevparams
  75.      dup /Weekday get {(Sun )(Mon )(Tue )(Wed )(Thu )(Fri )(Sat )} exch get
  76.      1 index /Month get 1 sub
  77.        {(Jan)(Feb)(Mar)(Apr)(May)(Jun)(Jul)(Aug)(Sep)(Oct)(Nov)(Dec)} exch get
  78.      concatstrings
  79.       {{/Day ( )} {/Hour ( )} {/Minute (:)} {/Second (:)} {/Year ( )}}
  80.       { dup 1 get 3 -1 roll exch concatstrings exch
  81.         0 get 2 index exch get
  82.         dup 10 lt { =string cvs (0) exch concatstrings } { =string cvs } ifelse
  83.         concatstrings
  84.       }
  85.      forall exch pop readonly def
  86.    /VMusage 100000 def
  87.    /version version readonly def
  88.    /Notice (No copyright on this font. Original available from moe.ipl.t.u-tokyo.ac.jp:/Font. Converted by wftopfa.ps (Aladdin Enterprises).) readonly def
  89.    /FullName fullname readonly def
  90.    /FamilyName FontBase readonly def
  91.    /Weight (Regular) readonly def
  92.    /ItalicAngle 0 def
  93.    /isFixedPitch true def
  94.    /UnderlinePosition 0 def
  95.    /UnderlineThickness 0 def
  96.  
  97.    end            % FontInfo
  98.  
  99.    /FontName fullname cvn def
  100.    /Encoding encoding def
  101.    /PaintType 0 def
  102.    /FontType 1 def
  103.    /FontMatrix [.001 0 0 .001 0 -0.16] readonly def
  104.    /UniqueID UniqueID def
  105.    /FontBBox [0 0 1000 1000] readonly def
  106.  
  107.    /Private 20 dict def
  108.    Private begin
  109.  
  110.    /-| {string currentfile exch readstring pop} readonly def
  111.    /|- {readonly def} readonly def
  112.    /| {readonly put} readonly def
  113.    /BlueValues [] readonly def
  114.    /OtherBlues [] readonly def
  115.    /MinFeature {16 16} readonly def
  116.    /StdHW StdHW def
  117.    /StdVW StdVW def
  118.    /ForceBold false def
  119.    /password 5839 def
  120.    /UniqueID UniqueID def
  121.    /OtherSubrs [] readonly def
  122.    /Subrs [
  123.      (\020\2771p|\020\024\020=-\223D\\\342R) readonly
  124.      (\020\2771py\274\366Uz) readonly
  125.      (\020\2771py\275\304\236i) readonly
  126.      (\020\2771p\371) readonly
  127.      (\020\2771p~\266+6\034\3446z) readonly
  128.    ] readonly def
  129.  
  130.    end            % Private
  131.  
  132.    /CharStrings 256 dict def
  133.    chars
  134.     { exch =string cvs
  135.       dup 0 get highcode eq
  136.        { 1 get encoding exch get exch CharStrings 3 1 roll put }
  137.        { pop pop }
  138.       ifelse
  139.     }
  140.    forall
  141.  
  142.    end            % Font
  143.  
  144.    Font /FontName get Font definefont setfont
  145.    (%stdout) (w) file writefont
  146.  } bind def
  147.  
  148. % Scan the command line and process files.
  149. /options mark
  150.   /version { 2 copy get /version exch def 1 add } bind
  151.   /StdHW { 2 copy get cvx exec /StdHW exch def 1 add } bind
  152.   /StdVW { 2 copy get cvx exec /StdVW exch def 1 add } bind
  153.   /UniqueId { 2 copy get cvi /UniqueID exch def 1 add } bind
  154.   /UniqueID 1 index
  155.   /FontBase { 2 copy get /FontBase exch def 1 add } bind
  156.   /StdEnc { /StdEncMode true def } bind
  157.   /CustomEnc { /CustomEncMode true def } bind
  158.   /Binary { /Binary true def } bind
  159.   /noEncrypt { /Encrypt false def } bind
  160. .dicttomark def
  161. /wftopfa        % [(arg1) ...] wftopfa -
  162.  { init dup 0
  163.     { dup 2 index length ge { exit } if
  164.       2 copy get exch 1 add exch
  165.       options 1 index .knownget { exch pop exec } { readdefs } ifelse
  166.     }
  167.    loop pop pop
  168.    wrfont_dict /binary_CharStrings Binary put
  169.    wrfont_dict /eexec_encrypt Encrypt put
  170.    wrfont_dict /name_all_Encodings CustomEncMode put
  171.    writepfa
  172.  } bind def
  173.  
  174. end                % wftopfa_dict
  175.  
  176. /wftopfa
  177.  { mark exch wftopfa_dict begin /saved save def { wftopfa } exec false%stopped
  178.     { cleartomark true } { cleartomark false } ifelse
  179.    saved end restore { stop } if
  180.  } bind def
  181.  
  182. [ shellarguments
  183.  { ] wftopfa }
  184.  { pop }
  185. ifelse
  186.  
  187. % ---------------- Root font ---------------- %
  188.  
  189. % Define the Encoding for the root font.
  190. /wfrootencoding
  191. % \x00-\x3F
  192.   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  193.   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  194.   0  1  2  3  4  5  6  7  8  0  0  0  0  0  0  0
  195.   9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  196. % \x40-\x7F
  197.  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  198.  41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  199.  57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  200.  73 74 75 76 77  0  0  0  0  0  0  0  0  0  0  0
  201. % \x80-\xFF
  202. 128 copy
  203. 256 packedarray def
  204.  
  205. % Define the template for the root font dictionary.
  206. /wfrootfontdict mark
  207.   /FontType 0
  208.   /FontMatrix [1 0 0 1 0 0]
  209.   /FMapType 2
  210.   /Encoding wfrootencoding
  211. .dicttomark def
  212.  
  213. % Define a dummy (placeholder) Type 1 font for the FDepVector.
  214. /type1dummyfont        % <fontname> type1dummyfont <font>
  215.  { mark /FontName 3 -1 roll
  216.    /FontType 1
  217.    /FontMatrix [.001 0 0 .001 0 0]
  218.    /FontBBox [0 0 1000 1000]
  219.    /Encoding /KanjiSubEncoding findencoding
  220.    /CharStrings 0 dict
  221.    /Private mark /BlueValues [] /password 5839 .dicttomark
  222.    .dicttomark dup /FontName get exch definefont
  223.  } bind def
  224.  
  225. % Write a root font.  Again, wrfont.ps does most of the work.
  226. /makerootfont        % <rootname> makerootfont <font>
  227.  { wfrootfontdict dup length 4 add    % FontName, FDepVector, PrefEnc, FID
  228.    dict copy begin
  229.    cvlit /FontName exch def
  230.    4 dict begin
  231.    /len FontName length def
  232.    /str len 4 add string def
  233.    FontName str cvs pop
  234.    str len (.r) putinterval
  235.    /FDepVector [ 16#21 1 16#74
  236.     { dup wfrootencoding exch get 0 eq
  237.        { pop
  238.        }
  239.        { 16 str len 2 add 2 getinterval cvrs pop
  240.          str cvn type1dummyfont
  241.        }
  242.       ifelse
  243.     }
  244.    for end counttomark -1 roll dup counttomark 2 roll
  245.    ] def
  246.    FontName currentdict end definefont
  247.  } bind def
  248. /writerootfont        % <rootname> writerootfont -
  249.  { save exch makerootfont setfont (%stdout) (w) file writefont restore
  250.  } bind def
  251.  
  252. % ---------------- Converting entire fonts ---------------- %
  253.  
  254. % Define the directory where the Wadalab fonts are stored.
  255. /wfdir (/home/ghost/kanji/w) def
  256.  
  257. % Convert an entire Wadalab font.
  258. /writeentirefont    % <fontname> <template*> writeentirefont -
  259.  { 2 dict begin
  260.    /templates exch def
  261.    /fontname exch def
  262.    [ templates
  263.       { wfdir (/) concatstrings exch concatstrings { copystring }
  264.     100 string filenameforall
  265.       }
  266.      forall
  267.      wfdir (/wadalab-sym/*.ps) concatstrings { copystring }
  268.        100 string filenameforall
  269.    ]
  270.    (%!\n) print
  271.     { /currentuserparams where
  272.        { pop currentuserparams /VMReclaim get -2 vmreclaim { vmreclaim } }
  273.        { { } }
  274.       ifelse
  275.     } == (exec\n) print
  276.    (/KanjiSubEncoding ) print /KanjiSubEncoding findencoding ==
  277.      (readonly def\n) print
  278.     { (%stderr) (w) file dup 2 index write== flushfile
  279.        mark exch (CustomEnc) (Binary) (noEncrypt)
  280.        (FontBase) fontname counttomark -1 roll ] wftopfa
  281.     }
  282.    forall
  283.    fontname cvn writerootfont
  284.    (exec\n) print
  285.    end
  286.  } def            % don't bind, so we can print the procedure
  287.  
  288. % Convert the Wadalab JIS 1&2 SaiMincho font.
  289. % To invoke this from the command line,
  290. %    gs -dNODISPLAY -q wftopfa.ps -c writeSaiMincho0 flush quit >wmin0.ps
  291. % To make the resulting font loadable on demand, add to the Fontmap file:
  292. %    /Wadalab-SaiMincho (wmin0.ps) ;
  293. /writeSaiMincho0
  294.  { (Wadalab-SaiMincho) [ (wadalab-mincho-0-8/*.ps) ] writeentirefont
  295.  } bind def
  296.